{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5f37b5ff-adf0-47ae-bca7-8adf02d2b9e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "开始生成第二部分图表 (11-20)...\n",
      "✅ 图表 11 生成完成\n",
      "✅ 图表 12 生成完成\n",
      "✅ 图表 13 生成完成\n",
      "✅ 图表 14 生成完成\n",
      "✅ 图表 15 生成完成\n",
      "✅ 图表 16 生成完成\n",
      "✅ 图表 17 生成完成\n",
      "✅ 图表 18 生成完成\n",
      "✅ 图表 19 生成完成\n",
      "✅ 图表 20 生成完成\n",
      "🎉 第二部分图表已保存到: D:\\数据分析及可视化\\图表\n"
     ]
    }
   ],
   "source": [
    "# visualization_part2_fixed.py\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import numpy as np\n",
    "from matplotlib.patches import Patch, Circle, Wedge\n",
    "import matplotlib as mpl\n",
    "from scipy import stats\n",
    "import os\n",
    "\n",
    "# 设置中文字体\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei']\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "\n",
    "# 创建保存目录\n",
    "output_dir = r\"D:\\数据分析及可视化\\图表\"\n",
    "os.makedirs(output_dir, exist_ok=True)\n",
    "\n",
    "class VisualizationPart2:\n",
    "    def __init__(self, data_path):\n",
    "        self.df = pd.read_excel(data_path)\n",
    "        self.colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7', \n",
    "                      '#DDA0DD', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E9']\n",
    "        \n",
    "    def chart11_diamond_trend(self):\n",
    "        \"\"\"11. 菱形走势图 - 完成率趋势\"\"\"\n",
    "        plt.figure(figsize=(14, 8))\n",
    "        \n",
    "        # 模拟完成率数据\n",
    "        months = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月']\n",
    "        completion_rates = [0.65, 0.72, 0.68, 0.85, 0.78, 0.82, 0.88, 0.91]\n",
    "        \n",
    "        # 创建菱形标记的折线图\n",
    "        plt.plot(months, completion_rates, color='#E74C3C', linewidth=2, alpha=0.6)\n",
    "        plt.scatter(months, completion_rates, marker='D', s=150, color='#3498DB', \n",
    "                   edgecolors='white', linewidth=2, zorder=5)\n",
    "        \n",
    "        # 添加数值标签\n",
    "        for i, (month, rate) in enumerate(zip(months, completion_rates)):\n",
    "            plt.annotate(f'{rate:.1%}', xy=(i, rate), xytext=(i, rate + 0.03),\n",
    "                        ha='center', va='bottom', fontsize=11, fontweight='bold',\n",
    "                        bbox=dict(boxstyle=\"round,pad=0.3\", facecolor='lightyellow', alpha=0.8))\n",
    "        \n",
    "        # 添加目标线\n",
    "        target_rate = 0.75\n",
    "        plt.axhline(y=target_rate, color='green', linestyle='--', linewidth=2, \n",
    "                   label=f'目标完成率: {target_rate:.0%}')\n",
    "        \n",
    "        # 填充高于目标线的区域\n",
    "        plt.fill_between(months, completion_rates, target_rate, \n",
    "                        where=np.array(completion_rates) >= target_rate,\n",
    "                        color='lightgreen', alpha=0.3)\n",
    "        \n",
    "        plt.title('月度完成率走势 - 菱形标记图', fontsize=16, fontweight='bold', pad=20)\n",
    "        plt.xlabel('月份', fontsize=12)\n",
    "        plt.ylabel('完成率', fontsize=12)\n",
    "        plt.ylim(0.5, 1.0)\n",
    "        plt.grid(True, alpha=0.3)\n",
    "        plt.legend()\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/11_菱形走势图.png', dpi=300, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart12_comparison_line(self):\n",
    "        \"\"\"12. 对比折线图 - 年度销售对比\"\"\"\n",
    "        plt.figure(figsize=(14, 8))\n",
    "        \n",
    "        # 模拟两年销售数据\n",
    "        months = ['1月', '2月', '3月', '4月', '5月', '6月']\n",
    "        sales_2023 = [45000, 52000, 61000, 58000, 72000, 68000]\n",
    "        sales_2024 = [48000, 56000, 65000, 62000, 78000, 85000]\n",
    "        \n",
    "        # 绘制对比折线\n",
    "        plt.plot(months, sales_2023, marker='o', linewidth=3, markersize=8,\n",
    "                color='#3498DB', label='2023年', alpha=0.8)\n",
    "        plt.plot(months, sales_2024, marker='s', linewidth=3, markersize=8,\n",
    "                color='#E74C3C', label='2024年', alpha=0.8)\n",
    "        \n",
    "        # 添加数值标签\n",
    "        for i, (sales23, sales24) in enumerate(zip(sales_2023, sales_2024)):\n",
    "            plt.text(i, sales23 + 2000, f'{sales23/1000:.0f}K', ha='center', va='bottom', \n",
    "                    fontsize=9, color='#3498DB', fontweight='bold')\n",
    "            plt.text(i, sales24 + 2000, f'{sales24/1000:.0f}K', ha='center', va='bottom', \n",
    "                    fontsize=9, color='#E74C3C', fontweight='bold')\n",
    "        \n",
    "        # 计算增长率\n",
    "        growth_rates = [(s24 - s23) / s23 * 100 for s23, s24 in zip(sales_2023, sales_2024)]\n",
    "        \n",
    "        # 添加增长率标注\n",
    "        for i, rate in enumerate(growth_rates):\n",
    "            color = 'green' if rate > 0 else 'red'\n",
    "            plt.annotate(f'{rate:+.1f}%', xy=(i, (sales_2023[i] + sales_2024[i])/2),\n",
    "                        xytext=(i, (sales_2023[i] + sales_2024[i])/2 + 5000),\n",
    "                        ha='center', va='bottom', fontsize=10, color=color,\n",
    "                        arrowprops=dict(arrowstyle='->', color=color, lw=1))\n",
    "        \n",
    "        plt.title('年度销售对比 - 对比折线图', fontsize=16, fontweight='bold', pad=20)\n",
    "        plt.xlabel('月份', fontsize=12)\n",
    "        plt.ylabel('销售额 (元)', fontsize=12)\n",
    "        plt.legend()\n",
    "        plt.grid(True, alpha=0.3)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/12_对比折线图.png', dpi=300, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart13_single_value_donut(self):\n",
    "        \"\"\"13. 单值圆环图 - 整体完成率\"\"\"\n",
    "        fig, ax = plt.subplots(figsize=(10, 10))\n",
    "        \n",
    "        completion_rate = 0.85\n",
    "        remaining = 1 - completion_rate\n",
    "        \n",
    "        # 创建圆环图\n",
    "        wedges, texts = ax.pie([completion_rate, remaining], \n",
    "                              colors=['#3498DB', '#ECF0F1'],\n",
    "                              startangle=90,\n",
    "                              wedgeprops=dict(width=0.3, edgecolor='w'))\n",
    "        \n",
    "        # 添加中心文本\n",
    "        ax.text(0, 0, f'{completion_rate:.0%}', ha='center', va='center', \n",
    "               fontsize=42, fontweight='bold', color='#2C3E50')\n",
    "        ax.text(0, -0.15, '完成率', ha='center', va='center', \n",
    "               fontsize=16, color='#7F8C8D')\n",
    "        \n",
    "        # 添加装饰性元素\n",
    "        circle = plt.Circle((0, 0), 0.6, color='white')\n",
    "        ax.add_artist(circle)\n",
    "        \n",
    "        ax.set_aspect('equal')\n",
    "        plt.title('整体任务完成率 - 单值圆环图', fontsize=16, fontweight='bold', pad=20)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/13_单值圆环图.png', dpi=300, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart14_water_ball(self):\n",
    "        \"\"\"14. 水球图 - 库存周转率\"\"\"\n",
    "        fig, ax = plt.subplots(figsize=(8, 10))\n",
    "        \n",
    "        turnover_rate = 0.65\n",
    "        \n",
    "        # 创建水球容器\n",
    "        container = plt.Circle((0.5, 0.3), 0.4, color='lightblue', alpha=0.3, \n",
    "                              fill=False, linewidth=3)\n",
    "        ax.add_artist(container)\n",
    "        \n",
    "        # 创建水位\n",
    "        water_level = turnover_rate * 0.8  # 缩放水位高度\n",
    "        water = Wedge((0.5, 0.3), 0.4, 180, 0, width=0.4, \n",
    "                     color='#3498DB', alpha=0.7)\n",
    "        ax.add_artist(water)\n",
    "        \n",
    "        # 添加水位线\n",
    "        y_water = 0.3 - 0.4 + water_level * 0.8\n",
    "        ax.axhline(y=y_water, color='white', linestyle='--', alpha=0.8, linewidth=2)\n",
    "        \n",
    "        # 添加数值显示\n",
    "        ax.text(0.5, 0.3, f'{turnover_rate:.0%}', ha='center', va='center', \n",
    "               fontsize=36, fontweight='bold', color='#2C3E50')\n",
    "        ax.text(0.5, 0.15, '库存周转率', ha='center', va='center', \n",
    "               fontsize=14, color='#7F8C8D')\n",
    "        \n",
    "        # 添加波浪效果\n",
    "        x_wave = np.linspace(0.1, 0.9, 50)\n",
    "        y_wave = y_water + 0.02 * np.sin(10 * x_wave)\n",
    "        ax.plot(x_wave, y_wave, 'white', linewidth=2, alpha=0.8)\n",
    "        \n",
    "        ax.set_xlim(0, 1)\n",
    "        ax.set_ylim(-0.2, 1)\n",
    "        ax.set_aspect('equal')\n",
    "        ax.axis('off')\n",
    "        \n",
    "        plt.title('库存周转率水球图', fontsize=16, fontweight='bold', pad=20)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/14_水球图.png', dpi=300, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart15_wave_water_ball(self):\n",
    "        \"\"\"15. 波浪水球图 - 客户满意度\"\"\"\n",
    "        fig, ax = plt.subplots(figsize=(10, 8))\n",
    "        \n",
    "        satisfaction_rate = 0.78\n",
    "        \n",
    "        # 创建容器\n",
    "        container = plt.Circle((0.5, 0.5), 0.4, color='lightgray', alpha=0.2, \n",
    "                              fill=False, linewidth=4)\n",
    "        ax.add_artist(container)\n",
    "        \n",
    "        # 创建动态波浪效果\n",
    "        x = np.linspace(0.1, 0.9, 100)\n",
    "        \n",
    "        # 多层波浪\n",
    "        for i, (amp, freq, phase) in enumerate([(0.02, 8, 0), (0.015, 12, 0.5)]):\n",
    "            y_base = 0.5 - 0.4 + satisfaction_rate * 0.8\n",
    "            y_wave = y_base + amp * np.sin(freq * x + phase)\n",
    "            \n",
    "            ax.fill_between(x, y_wave, 0.1, color='#3498DB', alpha=0.6-0.2*i)\n",
    "        \n",
    "        # 添加中心文本\n",
    "        ax.text(0.5, 0.5, f'{satisfaction_rate:.0%}', ha='center', va='center', \n",
    "               fontsize=32, fontweight='bold', color='#2C3E50')\n",
    "        ax.text(0.5, 0.4, '客户满意度', ha='center', va='center', \n",
    "               fontsize=14, color='#7F8C8D')\n",
    "        \n",
    "        # 添加刻度\n",
    "        for i, rate in enumerate([0, 0.25, 0.5, 0.75, 1.0]):\n",
    "            y_pos = 0.1 + i * 0.2\n",
    "            ax.plot([0.45, 0.5], [y_pos, y_pos], 'k-', alpha=0.5)\n",
    "            ax.text(0.43, y_pos, f'{rate:.0%}', ha='right', va='center', fontsize=10)\n",
    "        \n",
    "        ax.set_xlim(0, 1)\n",
    "        ax.set_ylim(0.1, 0.9)\n",
    "        ax.set_aspect('equal')\n",
    "        ax.axis('off')\n",
    "        \n",
    "        plt.title('客户满意度波浪水球图', fontsize=16, fontweight='bold', pad=20)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/15_波浪水球图.png', dpi=300, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart16_jade_disc(self):\n",
    "        \"\"\"16. 玉玦图 - 年龄分布\"\"\"\n",
    "        fig, ax = plt.subplots(figsize=(12, 12))\n",
    "        \n",
    "        # 年龄分布数据\n",
    "        age_groups = ['<20岁', '20-30岁', '30-40岁', '40-50岁', '>50岁']\n",
    "        age_dist = [0.15, 0.35, 0.25, 0.15, 0.10]\n",
    "        colors = ['#FF9999', '#66B2FF', '#99FF99', '#FFB366', '#C299FF']\n",
    "        \n",
    "        # 创建玉玦图（环形图+缺口）\n",
    "        for i, (age_group, proportion, color) in enumerate(zip(age_groups, age_dist, colors)):\n",
    "            # 计算起始和结束角度（留出缺口）\n",
    "            start_angle = sum(age_dist[:i]) * 360 + i * 5  # 每个扇区间隔5度\n",
    "            end_angle = start_angle + proportion * 360\n",
    "            \n",
    "            # 绘制扇形\n",
    "            wedge = Wedge((0, 0), 1, start_angle, end_angle, width=0.6, \n",
    "                         facecolor=color, alpha=0.8, edgecolor='white', linewidth=2)\n",
    "            ax.add_artist(wedge)\n",
    "            \n",
    "            # 添加标签\n",
    "            mid_angle = np.radians((start_angle + end_angle) / 2)\n",
    "            label_x = 1.3 * np.cos(mid_angle)\n",
    "            label_y = 1.3 * np.sin(mid_angle)\n",
    "            \n",
    "            ax.text(label_x, label_y, f'{age_group}\\n{proportion:.1%}', \n",
    "                   ha='center', va='center', fontsize=11, fontweight='bold',\n",
    "                   bbox=dict(boxstyle=\"round,pad=0.3\", facecolor='white', alpha=0.8))\n",
    "        \n",
    "        # 添加中心文本\n",
    "        ax.text(0, 0, '年龄\\n分布', ha='center', va='center', \n",
    "               fontsize=16, fontweight='bold', color='#2C3E50')\n",
    "        \n",
    "        ax.set_xlim(-1.5, 1.5)\n",
    "        ax.set_ylim(-1.5, 1.5)\n",
    "        ax.set_aspect('equal')\n",
    "        ax.axis('off')\n",
    "        \n",
    "        plt.title('客户年龄分布 - 玉玦图', fontsize=16, fontweight='bold', pad=20)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/16_玉玦图.png', dpi=300, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart17_runway_chart(self):\n",
    "        \"\"\"17. 跑道图 - 各部门绩效对比（修复版）\"\"\"\n",
    "        # 部门绩效数据\n",
    "        departments = ['销售部', '市场部', '技术部', '运营部', '客服部', '财务部']\n",
    "        performance = [85, 78, 92, 65, 88, 72]\n",
    "        \n",
    "        # 创建极坐标子图\n",
    "        fig, ax = plt.subplots(figsize=(12, 12), subplot_kw=dict(projection='polar'))\n",
    "        \n",
    "        # 计算角度\n",
    "        angles = np.linspace(0, 2*np.pi, len(departments), endpoint=False)\n",
    "        width = 2 * np.pi / len(departments) * 0.8\n",
    "        \n",
    "        # 绘制条形\n",
    "        bars = ax.bar(angles, performance, width=width, \n",
    "                     color=self.colors, alpha=0.8, edgecolor='white', linewidth=2)\n",
    "        \n",
    "        # 设置极坐标参数\n",
    "        ax.set_theta_offset(np.pi / 2)  # 从顶部开始\n",
    "        ax.set_theta_direction(-1)      # 顺时针方向\n",
    "        \n",
    "        # 设置角度标签\n",
    "        ax.set_xticks(angles)\n",
    "        ax.set_xticklabels(departments, fontsize=12)\n",
    "        \n",
    "        # 设置径向标签\n",
    "        ax.set_ylim(0, 100)\n",
    "        ax.set_yticks([20, 40, 60, 80, 100])\n",
    "        ax.set_yticklabels(['20', '40', '60', '80', '100分'], fontsize=10)\n",
    "        ax.grid(True, alpha=0.3)\n",
    "        \n",
    "        # 添加数值标签\n",
    "        for angle, perf, bar in zip(angles, performance, bars):\n",
    "            # 在条形外部添加标签\n",
    "            x = angle\n",
    "            y = perf + 5\n",
    "            ax.text(x, y, f'{perf}分', ha='center', va='center', \n",
    "                   fontsize=11, fontweight='bold',\n",
    "                   bbox=dict(boxstyle=\"round,pad=0.3\", facecolor='white', alpha=0.9))\n",
    "        \n",
    "        plt.title('各部门绩效对比 - 跑道图', fontsize=16, fontweight='bold', pad=30)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/17_跑道图.png', dpi=300, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart18_nightingale_rose(self):\n",
    "        \"\"\"18. 南丁格尔圆饼图 - 商品类别销售\"\"\"\n",
    "        fig, ax = plt.subplots(figsize=(12, 10))\n",
    "        \n",
    "        # 商品类别销售数据\n",
    "        categories = ['上衣', '裤子', '裙子', '外套', '配件', '鞋类']\n",
    "        sales = [45000, 32000, 28000, 38000, 15000, 22000]\n",
    "        colors = plt.cm.Set3(np.linspace(0, 1, len(categories)))\n",
    "        \n",
    "        # 创建南丁格尔玫瑰图（不等半径的扇形）\n",
    "        max_radius = max(sales) / 1000\n",
    "        radii = [sales[i] / 1000 for i in range(len(sales))]\n",
    "        \n",
    "        angles = np.linspace(0, 2*np.pi, len(categories), endpoint=False)\n",
    "        width = 2 * np.pi / len(categories)\n",
    "        \n",
    "        for i, (category, radius, angle, color) in enumerate(zip(categories, radii, angles, colors)):\n",
    "            # 绘制扇形（半径与销售额成正比）\n",
    "            wedge = Wedge((0, 0), radius, np.degrees(angle), np.degrees(angle + width), \n",
    "                         facecolor=color, alpha=0.8, edgecolor='white', linewidth=2)\n",
    "            ax.add_artist(wedge)\n",
    "            \n",
    "            # 添加标签\n",
    "            label_angle = angle + width / 2\n",
    "            label_radius = radius * 0.5\n",
    "            x = label_radius * np.cos(label_angle)\n",
    "            y = label_radius * np.sin(label_angle)\n",
    "            \n",
    "            ax.text(x, y, f'{category}\\n{sales[i]:,}元', \n",
    "                   ha='center', va='center', fontsize=10, fontweight='bold',\n",
    "                   bbox=dict(boxstyle=\"round,pad=0.3\", facecolor='white', alpha=0.9))\n",
    "        \n",
    "        ax.set_xlim(-max_radius*1.2, max_radius*1.2)\n",
    "        ax.set_ylim(-max_radius*1.2, max_radius*1.2)\n",
    "        ax.set_aspect('equal')\n",
    "        ax.axis('off')\n",
    "        \n",
    "        plt.title('商品类别销售额 - 南丁格尔玫瑰图', fontsize=16, fontweight='bold', pad=20)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/18_南丁格尔圆饼图.png', dpi=300, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart19_nightingale_donut(self):\n",
    "        \"\"\"19. 南丁格尔圆环图 - 价格区间分布\"\"\"\n",
    "        fig, ax = plt.subplots(figsize=(12, 10))\n",
    "        \n",
    "        # 价格区间数据\n",
    "        price_ranges = ['0-100元', '100-200元', '200-300元', '300-500元', '500+元']\n",
    "        distribution = [0.25, 0.35, 0.20, 0.15, 0.05]\n",
    "        colors = plt.cm.viridis(np.linspace(0, 1, len(price_ranges)))\n",
    "        \n",
    "        # 创建多层圆环图\n",
    "        radii = [0.6, 0.8, 1.0, 1.2, 1.4]  # 不同半径\n",
    "        \n",
    "        for i, (price_range, prop, radius, color) in enumerate(zip(price_ranges, distribution, radii, colors)):\n",
    "            # 计算扇形角度\n",
    "            start_angle = 0\n",
    "            end_angle = prop * 360\n",
    "            \n",
    "            # 绘制圆环段\n",
    "            wedge = Wedge((0, 0), radius, start_angle, end_angle, width=0.15,\n",
    "                         facecolor=color, alpha=0.8, edgecolor='white', linewidth=1)\n",
    "            ax.add_artist(wedge)\n",
    "            \n",
    "            # 添加标签\n",
    "            mid_angle = np.radians((start_angle + end_angle) / 2)\n",
    "            label_x = (radius + 0.1) * np.cos(mid_angle)\n",
    "            label_y = (radius + 0.1) * np.sin(mid_angle)\n",
    "            \n",
    "            ax.text(label_x, label_y, f'{price_range}\\n{prop:.1%}', \n",
    "                   ha='center', va='center', fontsize=9, fontweight='bold',\n",
    "                   bbox=dict(boxstyle=\"round,pad=0.2\", facecolor='white', alpha=0.8))\n",
    "        \n",
    "        # 添加中心文本\n",
    "        ax.text(0, 0, '价格\\n分布', ha='center', va='center', \n",
    "               fontsize=14, fontweight='bold', color='#2C3E50')\n",
    "        \n",
    "        ax.set_xlim(-1.6, 1.6)\n",
    "        ax.set_ylim(-1.6, 1.6)\n",
    "        ax.set_aspect('equal')\n",
    "        ax.axis('off')\n",
    "        \n",
    "        plt.title('商品价格区间分布 - 南丁格尔圆环图', fontsize=16, fontweight='bold', pad=20)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/19_南丁格尔圆环图.png', dpi=300, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart20_dashboard_gauge(self):\n",
    "        \"\"\"20. 仪表盘图 - 销售目标完成度\"\"\"\n",
    "        fig, ax = plt.subplots(figsize=(12, 8))\n",
    "        \n",
    "        completion = 76  # 完成百分比\n",
    "        \n",
    "        # 绘制半圆仪表盘\n",
    "        theta = np.linspace(0, np.pi, 100)\n",
    "        r = np.ones(100) * 5\n",
    "        \n",
    "        # 颜色分段（红-黄-绿）\n",
    "        colors = []\n",
    "        for angle in theta:\n",
    "            if angle < np.pi/3:\n",
    "                colors.append('#FF6B6B')  # 红色\n",
    "            elif angle < 2*np.pi/3:\n",
    "                colors.append('#FFEAA7')  # 黄色\n",
    "            else:\n",
    "                colors.append('#96CEB4')  # 绿色\n",
    "        \n",
    "        # 绘制彩色背景\n",
    "        for i in range(len(theta)-1):\n",
    "            ax.fill_betweenx([0, 5], theta[i], theta[i+1], \n",
    "                           color=colors[i], alpha=0.3)\n",
    "        \n",
    "        # 绘制刻度\n",
    "        for angle in np.linspace(0, np.pi, 7):\n",
    "            ax.plot([angle, angle], [4.8, 5.2], 'k-', linewidth=2)\n",
    "            percent = int(angle / np.pi * 100)\n",
    "            ax.text(angle, 4.5, f'{percent}%', ha='center', va='top', fontsize=10)\n",
    "        \n",
    "        # 绘制指针\n",
    "        pointer_angle = completion / 100 * np.pi\n",
    "        ax.plot([0, pointer_angle], [0, 4.5], 'r-', linewidth=6, alpha=0.8)\n",
    "        \n",
    "        # 添加中心圆点\n",
    "        ax.plot(0, 0, 'ro', markersize=12, markeredgecolor='darkred', markeredgewidth=2)\n",
    "        \n",
    "        # 添加数值显示\n",
    "        ax.text(np.pi/2, 2, f'{completion}%', ha='center', va='center', \n",
    "               fontsize=36, fontweight='bold', color='red')\n",
    "        ax.text(np.pi/2, 1, '目标完成度', ha='center', va='center', \n",
    "               fontsize=16, color='gray')\n",
    "        \n",
    "        ax.set_xlim(-0.5, np.pi + 0.5)\n",
    "        ax.set_ylim(-1, 6)\n",
    "        ax.set_aspect('equal')\n",
    "        ax.axis('off')\n",
    "        \n",
    "        plt.title('销售目标完成度仪表盘', fontsize=16, fontweight='bold', pad=20)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/20_仪表盘图.png', dpi=300, bbox_inches='tight')\n",
    "        plt.close()\n",
    "    \n",
    "    def generate_all_charts(self):\n",
    "        \"\"\"生成所有图表\"\"\"\n",
    "        print(\"开始生成第二部分图表 (11-20)...\")\n",
    "        \n",
    "        charts = [\n",
    "            self.chart11_diamond_trend,\n",
    "            self.chart12_comparison_line,\n",
    "            self.chart13_single_value_donut,\n",
    "            self.chart14_water_ball,\n",
    "            self.chart15_wave_water_ball,\n",
    "            self.chart16_jade_disc,\n",
    "            self.chart17_runway_chart,\n",
    "            self.chart18_nightingale_rose,\n",
    "            self.chart19_nightingale_donut,\n",
    "            self.chart20_dashboard_gauge\n",
    "        ]\n",
    "        \n",
    "        for i, chart_func in enumerate(charts, 11):\n",
    "            try:\n",
    "                chart_func()\n",
    "                print(f\"✅ 图表 {i} 生成完成\")\n",
    "            except Exception as e:\n",
    "                print(f\"❌ 图表 {i} 生成失败: {str(e)}\")\n",
    "                import traceback\n",
    "                traceback.print_exc()\n",
    "        \n",
    "        print(f\"🎉 第二部分图表已保存到: {output_dir}\")\n",
    "\n",
    "# 运行第二部分\n",
    "if __name__ == \"__main__\":\n",
    "    data_path = r\"D:\\数据分析及可视化\\erp_order_data.xlsx\"\n",
    "    viz2 = VisualizationPart2(data_path)\n",
    "    viz2.generate_all_charts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67ccbef8-43ac-4c5a-acda-c8063af65a17",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
